package com.hilin.base.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hilin.entity.po.AccountInfoPo;
import com.hilin.entity.po.OrgInfoPo;
import com.hilin.entity.po.SysAccessPo;
import com.hilin.entity.po.SysRolePo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IAccountMapper extends BaseMapper<AccountInfoPo> {

    @Select("select t2.* from account_info t1,org_info t2\n" +
            "where" +
            " t1.account_id = #{accountId}\n" +
            "and t1.org_id=t2.org_id")
    List<OrgInfoPo> getAccountOrgList(@Param("accountId") String accountId);

    @Select("select t1.*\n" +
            "from sys_access t1,\n" +
            "     account_role t2,\n" +
            "     sys_role t3\n" +
            "where " +
            " <if test='account!=null'>t1.account_id = #{accountId} and </if>\n" +
            "  t3.org_id = #{orgId}\n" +
            "  and t1.access_id = t2.account_id\n" +
            "  and t2.role_id = t3.role_id")
    List<SysAccessPo> getAllAccess(@Param("accountId") String accountId, @Param("orgId") Long orgId);

    @Select("<script>" +
            "select t1.*\n" +
            "from account_role t1,\n" +
            "     sys_role t2\n" +
            "where " +
            " <if test='account!=null'>t1.account_id = #{accountId} and </if>\n" +
            "  t2.org_id = #{orgId} and \n " +
            " t1.role_id = t2.role_id" +
            "</script>")
    List<SysRolePo> getAllRole(@Param("accountId") String accountId, @Param("orgId") Long orgId);

    @Select("select t1.*\n" +
            "from sys_access t1,\n" +
            "     sys_role_access t2,\n" +
            "     sys_role t3\n" +
            "where t2.role_id = #{roleId}\n" +
            "  and t3.org_id =#{orgId}\n" +
            "  and t1.access_id = t2.access_id\n" +
            "  and t3.role_id = t2.role_id")
    List<SysAccessPo> getRoleAccess(@Param("roleId") Long roleId, @Param("orgId") Long orgId);
}
